<?php
namespace app\member\Controller;
use app\member\controller\BaseUser;
class Student extends BaseUser{
    public function index(){
       $student = getSession("user");
       $this->assign("student",$student);
       return  $this->fetch();
    }
    
    public function resetpwd(){
        if (request()->isPost()){
            try {
                $data = input();
                if (!checkpwd($data['id'], $data['old_password'])){
                    die("原密码不正确！");
                }
                if ($data['password']!=$data['repassword']){
                    die("两次输入密码不一致！");
                }
                $data['password'] = md5($data['password']);
                unset($data['repassword']);
                unset($data['old_password']);
                $res = db("member")->update($data);
                if ($res){
                    die("密码修改成功！");
                }else{
                    die("密码修改失败！");
                }  
            } catch (\Exception $e) {
                die($e->getMessage());
            }
            
        }
        $student = getSession("user");
        $this->assign("student",$student);
        return $this->fetch();
    }
}